Imports System 
Imports System.Text 
Imports System.Data
Imports System.Data.SqlClient
Imports System.Data.Common
Imports System.Collections
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Configuration 
Imports System.Xml 
Imports System.Xml.Serialization
Imports SubSonic 
Imports SubSonic.Utilities
Namespace Data
    ''' <summary>
    ''' Controller class for Teams
    ''' </summary>
		<System.ComponentModel.DataObject()> Public Partial Class TeamsController
    
        ' Preload our schema..
        Dim thisSchemaLoad As Teams = New Teams()
        Private strUserName As String = String.Empty
        Protected ReadOnly Property UserName() As String
            Get
				If strUserName.Length = 0 Then
		        
    				If Not System.Web.HttpContext.Current Is Nothing Then
						strUserName = System.Web.HttpContext.Current.User.Identity.Name
					Else
		        		strUserName = System.Threading.Thread.CurrentPrincipal.Identity.Name
					End If
					Return strUserName
				End If
				Return strUserName
			End Get
        End Property
        <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchAll() As TeamsCollection
        
            Dim coll As TeamsCollection = New TeamsCollection()
            Dim qry As Query = New Query(Teams.Schema)
            coll.LoadAndCloseReader(qry.ExecuteReader())
            Return coll
            
        End Function
        <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchByID(ByVal Id As Object) As TeamsCollection 
        
            Dim coll As TeamsCollection = New TeamsCollection().Where("id", Id).Load()
            Return coll
        
        End Function
        
        <DataObjectMethod(DataObjectMethodType.Select, True)> Public Function FetchByQuery(ByVal qry As SubSonic.Query) As TeamsCollection 
        
            Dim coll As TeamsCollection = New TeamsCollection()
            coll.LoadAndCloseReader(qry.ExecuteReader())
            Return coll
        
        End Function
        <DataObjectMethod(DataObjectMethodType.Delete, True)> Public Function Delete(ByVal Id As Object) as Boolean
        
            Return (Teams.Delete(Id) = 1)
        
        End Function
        <DataObjectMethod(DataObjectMethodType.Delete, False)> Public Function Destroy(ByVal Id As Object) as Boolean
        
            Return (Teams.Destroy(Id) = 1)
        
        End Function
        
    	
	    ''' <summary>
	    ''' Inserts a record, can be used with the Object Data Source
	    ''' </summary>
        <DataObjectMethod(DataObjectMethodType.Insert, True)> Public Sub Insert(ByVal Name As String,ByVal SeasonID As Integer,ByVal LeaderMemId As Guid)
	   
		    Dim item As Teams = New Teams()
		    
            item.Name = Name
            
            item.SeasonID = SeasonID
            
            item.LeaderMemId = LeaderMemId
            
	    
		    item.Save(UserName)
	   
	   End Sub
    	
	    ''' <summary>
	    ''' Updates a record, can be used with the Object Data Source
	    ''' </summary>
        <DataObjectMethod(DataObjectMethodType.Update, True)> Public Sub Update(ByVal Id As Integer,ByVal Name As String,ByVal SeasonID As Integer,ByVal LeaderMemId As Guid)
	    
		    Dim item As Teams = New Teams()
		    
				item.Id = Id
				
				item.Name = Name
				
				item.SeasonID = SeasonID
				
				item.LeaderMemId = LeaderMemId
				
		    item.MarkOld()
		    item.Save(UserName)
	    
	    End Sub
    End Class
End Namespace
